package cn.com.homeyoda.aimate.aihealth.ui.health_manage;

import android.app.Application;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;

import androidx.annotation.NonNull;

import com.wzq.mvvmsmart.event.StateLiveData;
import com.wzq.mvvmsmart.http.ResponseThrowable;
import com.wzq.mvvmsmart.utils.KLog;
import com.wzq.mvvmsmart.utils.RxUtils;
import com.wzq.mvvmsmart.utils.ToastUtils;

import java.util.ArrayList;
import java.util.List;

import cn.com.homeyoda.aimate.aihealth.R;
import cn.com.homeyoda.aimate.aihealth.base.BaseViewModel;
import cn.com.homeyoda.aimate.aihealth.bean.ChronicDiseaseItemBean;
import cn.com.homeyoda.aimate.aihealth.bean.FaceInfoBean;
import cn.com.homeyoda.aimate.aihealth.bean.IsShowCompleteInfoBean;
import cn.com.homeyoda.aimate.aihealth.bean.KePuBean;
import cn.com.homeyoda.aimate.aihealth.bean.MyselfPlanBean;
import cn.com.homeyoda.aimate.aihealth.bean.PopularListBean;
import cn.com.homeyoda.aimate.aihealth.data.Repository;
import cn.com.homeyoda.aimate.aihealth.manager.UserInfoManager;
import cn.com.homeyoda.aimate.aihealth.ui.videoinspect.VideoInspectModel;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public class HealthManageViewModel extends BaseViewModel<Repository> {

    private List<KePuBean> kePuList = new ArrayList<>();
    public StateLiveData<List<PopularListBean.RowsBean>> kePuData;




    public HealthManageViewModel(@NonNull Application application, Repository model) {
        super(application, model);
        kePuData = new StateLiveData<>();
    }

    public void getKePuData(String type, String pageNum, String pageSize) {
//        KePuBean kePuBean = new KePuBean();
//        kePuBean.setContent("“二手烟”害人病，“二手酒”要人命");
//        kePuBean.setName("张三");
//        kePuBean.setNum("10.8");
//        kePuBean.setTime("2025-02-28");
//        kePuBean.setImgPath(BitmapFactory.decodeResource(getApplication().getResources(), R.mipmap.ic_kepu1));
//
//        KePuBean kePuBean1 = new KePuBean();
//        kePuBean1.setContent("吃一颗抵十颗苹果？这才是维 生素含量最高的三种水果");
//        kePuBean1.setName("李四");
//        kePuBean1.setNum("13.5");
//        kePuBean1.setTime("2025-02-27");
//        kePuBean1.setImgPath(BitmapFactory.decodeResource(getApplication().getResources(), R.mipmap.ic_kepu2));
//
//        KePuBean kePuBean2 = new KePuBean();
//        kePuBean2.setContent("吃一颗抵十颗苹果？这才是维 生素含量最高的三种水果");
//        kePuBean2.setName("王五");
//        kePuBean2.setNum("1.8");
//        kePuBean2.setTime("2025-02-18");
//        kePuBean2.setImgPath(BitmapFactory.decodeResource(getApplication().getResources(), R.mipmap.ic_kepu3));
//
//        KePuBean kePuBean3 = new KePuBean();
//        kePuBean3.setContent("吃一颗抵十颗苹果？这才是维 生素含量最高的三种水果。吃一颗抵十颗苹果？这才是维 生素含量最高的三种水果");
//        kePuBean3.setName("张三");
//        kePuBean3.setNum("8.8");
//        kePuBean3.setTime("2025-01-28");
//        kePuBean3.setImgPath(BitmapFactory.decodeResource(getApplication().getResources(), R.mipmap.ic_kepu4));
//
//        kePuList.add(kePuBean);
//        kePuList.add(kePuBean1);
//        kePuList.add(kePuBean2);
//        kePuList.add(kePuBean3);
//        kePuData.postSuccess();
//        kePuData.getValue().addAll(kePuList);
        //kePuData.postValueAndSuccess(kePuData.getValue());


        model.getPopularList(type, pageNum, pageSize)
                .compose(RxUtils.observableToMain())
                .compose(RxUtils.exceptionTransformer())
                .doOnSubscribe(HealthManageViewModel.this)
                .subscribe(new Observer<PopularListBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {
//                        stateIsShowData.postLoading();
                    }

                    @Override
                    public void onNext(PopularListBean popularListBean) {
                        if (popularListBean.getCode() == 200) {
                            //UploadVideoBean data = uploadVideoBeanBaseResponse2.getData();
                            //stateLiveData.postSuccess();
                            //stateLiveData.getValue().add(data);
                            kePuData.postValueAndSuccess(popularListBean.getRows());
                        }
                    }


                    @Override
                    public void onError(Throwable e) {
                        KLog.e("进入onError" + e.getMessage());
                        Log.i("huahua", "stateLiveData.getMessage()=====" + e.getMessage());
                        Log.i("huahua", "e.getMessage()=====" + e.getMessage().toString());
                        //关闭对话框
                        kePuData.postError();
                        if (e instanceof ResponseThrowable) {
                            ToastUtils.showShort(((ResponseThrowable) e).message);
                        }
                    }

                    @Override
                    public void onComplete() {
                        KLog.e("进入onComplete");
                        //请求刷新完成收回
                        kePuData.postIdle();

                    }
                });

    }

}
